<? 
    session_start();
	include ("core/conn.php");
	$db = get_conn();
	check_session();

?>
<html>
<head>
<link href="css/admin_styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form name='users' method='post' action='/core/clients.php' onsubmit='return checkdata(this)'>
  <table border='0' width="100%" align="center">
    <tr>
      <td ><div align="center">
        <h2>Usuarios</h2>
      </div></td>
    </tr>
    <tr>
      <td >&nbsp;</td>
    </tr>
    <tr>
      <td ><a href="users_form.php">Crear Nuevo Usuario</a></td>
    </tr>
    <tr>
      <td class="table_border">
      <?	
	  		$sql = "select u.*, l.number
					from users u, user_rol ur, rol r, `locations` l
					where u.id_user = ur.id_user and r.id_rol = ur.id_rol and u.id_location = l.id_location
					order by name";
			$result = mysql_query($sql);
			if($result){
			$counter=0; 
				$data ="<table width='100%' border='0' align='center'>";
				if(mysql_num_rows($result) > 0){
				
						$data .= 
						"<tr >
							<td align='left' class='table_header'>
								Nombre
							</td>
							<td align='left' class='table_header'>
								Fileal
							</td>
																				
						</tr>";				
					while($row = mysql_fetch_array($result)){
						$counter ++;
						if($row['phone1'] !=''){
							$phones.=$row['phone1'].' - ';
						}
						if($row['phone2'] !=''){
							$phones.=$row['phone2'].' - ';
						}
						if($row['phone3'] !=''){
							$phones.=$row['phone3'];
						}												
						

						$data .= 
						"<tr class='".$class_."'>
							<td align='left' class='texto'>
								<a  href='/users_form.php?id=".$row['id_user']."'>".htmlentities($row['name']." ".$row['lastname']." ".$row['lastname2'])." </a>
							</td>
							<td align='left' class='texto'>
								".$row['number']."
							</td>
																				
						</tr>";
						
						$phones ="";
					}//while
				}//if
				else{
					$data .= "<tr><td align='center'>No hay users registrados</td></tr>";			
				}
				$data .="</table>";
			}else{
					error_handling(__FUNCTION__.$sql,mysql_error());
			}
			echo $data;
			?></td>
    </tr>
  </table>
</form>
</body>
</html>
